//
//  ProductDetailInfoCell.m
//  MJApp
//
//  Created by John on 15/3/30.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "ProductDetailInfoCell.h"
@interface ProductDetailInfoCell()
@property (weak, nonatomic) IBOutlet UIImageView *image;
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *storeNum;
@property (weak, nonatomic) IBOutlet UILabel *size;
@property (weak, nonatomic) IBOutlet UILabel *colorLabel;
@property (nonatomic,strong)NSMutableDictionary *sizeDic;

@end
@implementation ProductDetailInfoCell

- (NSMutableDictionary *)sizeDic {
    
    if (!_sizeDic) {
        
        _sizeDic = [NSMutableDictionary dictionary];
    }
    return _sizeDic;
}

- (void)awakeFromNib {
    // Initialization code
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectSize:) name:@"selectSize" object:nil];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
+ (instancetype)cellForTableview:(UITableView *)tableview{

    static NSString * ID = @"ProductDetailInfoCell";
    ProductDetailInfoCell * cell = [tableview dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
      cell = [[NSBundle mainBundle] loadNibNamed:@"ProductDetailInfoCell" owner:nil options:nil].lastObject;
    }
    cell.cellH = 144;
  
    return cell;
}
- (IBAction)exitDetail:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(ProductDetailInfoCellExitDetail:)]) {
        [self.delegate ProductDetailInfoCellExitDetail:self];
    }
}
- (void)setInfoDic:(NSDictionary *)infoDic{

    [super setInfoDic:infoDic];
    self.priceLabel.text = [NSString stringWithFormat:@"￥%.2f~￥%.2f",[infoDic[@"price_low"] floatValue],[infoDic[@"price_high"] floatValue]];
    self.storeNum.text = [NSString stringWithFormat:@"库存%@件",infoDic[@"stockAll"]];
    NSString * imageUrl = [NSString stringWithFormat:@"%@%@",kUrl,infoDic[@"images"][0][@"image"]];
    [self.image sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil];
    
}

- (void)selectSize:(NSNotification *)notice {
    
    NSDictionary *dic = notice.userInfo;
    
    if (dic[@"color"]) {
        
        self.sizeDic[@"color"] = dic[@"color"];
    }
    if (dic[@"size"]) {
        self.sizeDic[@"size"] = dic[@"size"];
    }
    NSString *str = [NSString stringWithFormat:@"已选择：%@,%@",self.sizeDic[@"size"],self.sizeDic[@"color"]];
    self.size.text = str;
}

@end
